package com.yikaiye.android.yikaiye.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.DialogZengzhiBinding;

/**
 * 增值
 */
public class ZengZhiDialog {
    private final Dialog dialog;

    public ZengZhiDialog(Context context) {
        DialogZengzhiBinding binding = DialogZengzhiBinding.inflate(LayoutInflater.from(context));
        dialog = new Dialog(context, R.style.prompt_progress_dialog_dimenabled);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams((
                LinearLayout.LayoutParams.MATCH_PARENT), LinearLayout.LayoutParams.MATCH_PARENT);
        dialog.setContentView(binding.getRoot(), layoutParams);
        dialog.setCancelable(true);
        Window dialogWindow = dialog.getWindow();
        if (dialogWindow != null) {
            // 去除遮罩效果
//        dialogWindow.setDimAmount(0f);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            dialogWindow.setGravity(Gravity.BOTTOM);
            dialogWindow.setWindowAnimations(R.style.main_menu_animStyle);
            // lp.x = 266; // 新位置X坐标
            // lp.y = Utils.dip2px(activity, 300); // 新位置Y坐标
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            dialogWindow.setAttributes(lp);
        }
        binding.ivClose.setOnClickListener(v -> dismissDialog());
    }

    public void showDialog() {
        dialog.show();
    }

    public void dismissDialog() {
        if (dialog != null) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    }
}
